package ac.cns.inchoen.UIandroid;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import ac.cns.incheon.Adapter.ResDetailViewAdapter;
import ac.cns.incheon.handler.ResDetailHandler;
import ac.cns.incheon.model.ResDetailXmlDataModel;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class ResDetailViewActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_res_detail_view);

		URL url = null;
		ResDetailHandler xmlHandler = null;
		try {

			String strUrl = this.getIntent().getStringExtra("name");

			url = new URL(strUrl);
			SAXParserFactory parserModel = SAXParserFactory.newInstance();
			SAXParser concreteParser = parserModel.newSAXParser();
			XMLReader myReader = concreteParser.getXMLReader();
			xmlHandler = new ResDetailHandler();
			myReader.setContentHandler(xmlHandler);
			myReader.parse(new InputSource(url.openStream()));
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		List<ResDetailXmlDataModel> list = xmlHandler
				.getRestaurantXmlDataModelList();

		ResDetailViewAdapter adapter = new ResDetailViewAdapter(this, list);

		ListView listView = (ListView) findViewById(R.id.activity_res_detail_view);
		listView.setAdapter(adapter);

	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		getMenuInflater().inflate(R.menu.activity_res_detail_view, menu);
//		return true;
//	}

}
